<?php
include "include/config.inc.php";
if(!isset($_SESSION['s_activId']))
{
  header('location:checkLogin.php');
}

$today = date("d/m/y");
$loanArray = array();
$i=0;

$selectLoan = "SELECT loanId, party.partyName, item.itemId, value, loanAmount , item.itemName, weight, party.photo, itemlocation.itemlocationName, loanDate, monthlyInterest, monthlyInterestRs, loanVarNo
                 FROM loan
            LEFT JOIN party ON loan.partyId = party.partyId
            LEFT JOIN itemlocation ON loan.itemlocationId = itemlocation.itemlocationId
            LEFT JOIN item ON loan.itemId = item.itemId
                WHERE loan.loanId = ".$_REQUEST['loanId']."
                 AND isSold = 'N'
                  AND isDeleted = 'N'";
$selectLoanRes = mysql_query($selectLoan);
while($loanRow = mysql_fetch_array($selectLoanRes))
{
  $selectLoanAmount = "SELECT SUM(loanAmount) AS totaLoanAmount
                         FROM loan
                        WHERE itemId = ".$loanRow['itemId'];
  $selectLoanAmountRes                  = mysql_query($selectLoanAmount);
  $selectLoanAmountRow                  = mysql_fetch_array($selectLoanAmountRes);
  $loanArray[$i]['loanId']              = $loanRow['loanId'];
  $loanArray[$i]['partyName']           = $loanRow['partyName'];
  $loanArray[$i]['value']               = $loanRow['value'];
  $loanArray[$i]['loanAmount']          = $loanRow['loanAmount'];
  $loanArray[$i]['totalLoanOnThisItem'] = $selectLoanAmountRow['totaLoanAmount'];
  $loanArray[$i]['itemName']            = $loanRow['itemName'];
  $loanArray[$i]['weight']              = $loanRow['weight'];
  $loanArray[$i]['photo']               = $loanRow['photo'];
  $loanArray[$i]['itemlocationName']    = $loanRow['itemlocationName'];
  $loanArray[$i]['loanDate']            = date('d-m-Y',strtotime($loanRow['loanDate']));
  $loanArray[$i]['monthlyInterest']     = $loanRow['monthlyInterest'];
  $loanArray[$i]['monthlyInterestRs']   = $loanRow['monthlyInterestRs'];
  $loanArray[$i]['loanVarNo']           = $loanRow['loanVarNo'];
  $i++;
}
include("bottom.php");
$smarty->assign('loanArray',$loanArray);  
$smarty->display('loanListDetail.tpl');  
?>